unit directoryhelper;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, FileCtrl;

type
  link=^node;
  node=record
    filename: string;
    ModTime:  Integer;
    Attr:     Integer;
    l, r:     link
  end;

var
  head, tail: link;

implementation

{procedure TForm1.FormCreate(Sender: TObject);
begin
  new(tail);
  new(head);
  head^.filename:='';
  head^.r:=tail;
  head^.l:=tail;
end;}

function TreeInsert(Fname:string; q:link):link;
var
  st:link;
begin
  repeat
    st :=q;
    if fname < q^.filename then
      q := q^.l
    else
      q := q^.r;
  until q = tail;
  new(q);
  q^.filename := fname;
  q^.l := tail;
  q^.r := tail;
  if fname < st^.filename then
    st^.l := q
  else
    st^.r := q;
  TreeInsert := q;
end;


function FileLook(Filespec:string):boolean;
var
  x:link;
  validres, ModifiedTime:integer;
  SearchRec: TSearchRec;
  DirPath, FullName, Flname : string;

begin
  DirPath := ExtractFilePath(FileSpec);
  Result := DirectoryExists(DirPath);
  if not Result then
    exit;
  Flname := ExtractFileName(FileSpec);
  validres := FindFirst(FileSpec, faAnyFile, SearchRec);
  while validres=0 do
  begin
    if (SearchRec.Name[1] <> '.') then {not a directory}
    begin
      FullName := DirPath + LowerCase(SearchRec.Name);
      x := TreeInsert(FullName, head);
      ModifiedTime := FileAge(FullName);
        x^.ModTime := ModifiedTime;
      if (SearchRec.Attr and faDirectory>0) then
        FileLook(FullName+'\'+Flname);
    end;
    validres := FindNext(SearchRec);
  end;
end;

end.
